package top.hkyzf.study.leetcode.array;

import org.junit.Test;

/**
 * description: 
 * @author zhufeng
 * @date 2024/3/8 0008 9:54
 * @version V1.0
 */
public class 找出美丽数组的最小和_2834 {
    public int minimumPossibleSum(int n, int target) {
        int mod = (int) (Math.pow(10, 9) + 7);
        int middle = target >> 1;
        if (n > middle) {
            return (int)((((long) target + target + (n-middle-1)) * (n-middle) / 2 + (long) (1 + middle) * middle / 2) % mod);
        } else {
            return ((1 + n) * n / 2) % mod;
        }
    }

    @Test
    public void testMinimumPossibleSum () {
        int n = 1000000000;
        int target = 1000000000;
        System.out.println(minimumPossibleSum(n, target));
    }
}
